#include <iostream>
#include <map>

#include <GL/glut.h>

#include "world.h"

using namespace std;

World::World() : _objects(), _camera()
{
}

World::~World()
{
}

void World::put(Object* o)
{
	if (_selectIndex > 16777215)
	{
		// Handle error better
		cerr << "Too many objects in world!" << endl;
		return;
	}
	Color c(_selectIndex / 65536, _selectIndex / 256, _selectIndex % 256);
	o->setSelectColor(c);
	_objects[_selectIndex] = o;
	_selectIndex++;
}

Camera& World::getCamera()
{
	return _camera;
}

void World::draw()
{
	for (map<int, Object*>::iterator i = _objects.begin(); i != _objects.end(); i++)
	{
		glPushMatrix();
		i->second->moverot();
		i->second->draw();
		glPopMatrix();
	}
}

void World::act()
{
	for (map<int, Object*>::iterator i = _objects.begin(); i != _objects.end(); i++)
	{
		i->second->act();
	}
}
